package com.zbkj.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.common.model.client.agent.UserLocation;
import com.zbkj.service.dao.client.UserLocationDao;
import com.zbkj.service.service.UserLocationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户定位表 服务实现类
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Service
public class UserLocationServiceImpl extends ServiceImpl<UserLocationDao, UserLocation> implements UserLocationService {

    /**
     * 根据用户ID获取用户定位信息
     * @param userId 用户ID
     * @return UserLocation
     */
    @Override
    public UserLocation getByUserId(Integer userId) {
        LambdaQueryWrapper<UserLocation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserLocation::getUserId, userId);
        wrapper.eq(UserLocation::getIsDel, 0);
        wrapper.orderByDesc(UserLocation::getCreateTime);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    /**
     * 根据商户ID获取用户定位信息列表
     * @param merId 商户ID
     * @return UserLocation列表
     */
    @Override
    public List<UserLocation> getByMerId(Integer merId) {
        LambdaQueryWrapper<UserLocation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserLocation::getMerId, merId);
        wrapper.orderByDesc(UserLocation::getCreateTime);
        return list(wrapper);
    }

    /**
     * 根据行业类别获取用户定位信息列表
     * @param industry 行业类别
     * @return UserLocation列表
     */
    @Override
    public List<UserLocation> getByIndustry(String industry) {
        LambdaQueryWrapper<UserLocation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserLocation::getIndustry, industry);
        wrapper.orderByDesc(UserLocation::getCreateTime);
        return list(wrapper);
    }

    /**
     * 根据区域获取用户定位信息列表
     * @param region 区域
     * @return UserLocation列表
     */
    @Override
    public List<UserLocation> getByRegion(String region) {
        LambdaQueryWrapper<UserLocation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserLocation::getRegion, region);
        wrapper.orderByDesc(UserLocation::getCreateTime);
        return list(wrapper);
    }
}